package config

import (
	"fmt"
	"os"
	"path/filepath"

	"github.com/rs/zerolog"
	"github.com/rs/zerolog/log"
)

func InitZeroLog() {
	consoleWriter := zerolog.ConsoleWriter{
		Out:        os.Stdout,
		TimeFormat: "2006-01-02 15:04:05",
		FormatCaller: func(i interface{}) string {
			if i == nil {
				return ""
			}
			// Define ANSI escape codes for colors
			const (
				colorReset   = "\033[0m"
				colorRed     = "\033[31m"
				colorGreen   = "\033[32m"
				colorYellow  = "\033[33m"
				colorBlue    = "\033[34m"
				colorMagenta = "\033[35m"
				colorCyan    = "\033[36m"
				colorWhite   = "\033[37m"
				colorGray    = "\033[90m"
			)
			// Apply color to the caller output
			return fmt.Sprintf("%s[%s]%s", colorMagenta, filepath.Base(fmt.Sprintf("%s", i)), colorReset)
		},
	}
	multi := zerolog.MultiLevelWriter(consoleWriter)

	log.Logger = zerolog.New(multi).With().Timestamp().Caller().Logger()
}